﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ycdlib
{
	internal enum TokenType
	{
		Unknown,
		SYMBOL,
		INTEGER,
		DECIMAL,
		FLOAT,
		STRING,
		WITHSYMBOL,
		ALPHA,
		NUMALPHA,
		MLANG
	}

	internal class Token
	{
		TokenType tokenType;
		string value;
		int charactor;
		int col;
		int line;

		/// <summary>
		/// コンストラクタ
		/// </summary>
		/// <param name="tt">トークンの種別</param>
		/// <param name="v">値</param>
		/// <param name="L">行番号</param>
		/// <param name="C">列番号</param>
		public Token ( TokenType tt, String v, int L, int C )
		{
			tokenType = tt;
			value = v;
			charactor = 0;

			line = L;
			col = C;
		}


		/// <summary>
		/// コンストラクタ
		/// </summary>
		/// <param name="tt">トークンの種別</param>
		/// <param name="c">文字</param>
		/// <param name="L">行番号</param>
		/// <param name="C">列番号</param>
		public Token ( TokenType tt, int c, int L, int C )
		{
			tokenType = tt;
			value = null;
			charactor = c;

			line = L;
			col = C;
		}


		/// <summary>
		/// トークンの種別を取得できる
		/// </summary>
		public TokenType TokenType { get { return tokenType; } }
		/// <summary>
		/// トークンの値を取得できる
		/// </summary>
		public string Value { get { return value; } internal set { this.value = value; } }

		public int Line { get { return line; } }
		public int Col { get { return col; } }

		/// <summary>
		/// トークンが指定された記号であるか
		/// </summary>
		/// <param name="c"></param>
		/// <returns></returns>
		public bool IsEqual ( int c )
		{
			return tokenType==TokenType.SYMBOL && charactor==c;
		}


		/// <summary>
		/// 文字列化
		/// </summary>
		/// <returns></returns>
		public override string ToString ()
		{
			string __result = string.Empty;
			switch( tokenType )
			{
				case TokenType.Unknown:
					__result = "[Unknown]";
					break;
				case TokenType.SYMBOL:
					__result = new string( new char[] {'\'',(char)charactor, '\''} );
					break;
				default:
					__result = value;
					break;
			}
			return __result;
		}
	}
}
